import cv2
import mediapipe as mp
import time


cap = cv2.VideoCapture(0)
Ptime = 0
mpFaceMesh = mp.solutions.face_mesh
FaceMesh = mpFaceMesh.FaceMesh(max_num_faces=2)
mpDraw = mp.solutions.drawing_utils
faceSpec = mpDraw.DrawingSpec(thickness=1,circle_radius=2)
while True:
    ret,frame = cap.read()
    frameRGB = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    result = FaceMesh.process(frameRGB)
    if result.multi_face_landmarks:
        for faceLms in result.multi_face_landmarks:
            mpDraw.draw_landmarks(frame,faceLms,mpFaceMesh.FACEMESH_CONTOURS,faceSpec,faceSpec)
            for id,lm in enumerate(faceLms.landmark):
                h,w,c = frame.shape
                x,y = int(lm.x*w),int(lm.y*h)
                print(id,x,y)
    Ctime = time.time()
    fps = 1/(Ctime-Ptime)
    Ptime = Ctime
    cv2.putText(frame,'FPS:'+str(int(fps)),(10,70),cv2.FONT_HERSHEY_PLAIN,3,(0,255,0),2)
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break